<template>
  <el-form ref="queryForm" :inline="true" :model="queryModel">
    <template v-for="(item, index) in form" :key="index">
      <FormItem :item="item" v-bind="item" v-model="queryModel[item.model]" />
    </template>
    <el-form-item>
      <el-button type="primary" @click="handleQuery">查询</el-button>
      <el-button @click="handleReset">重置</el-button>
    </el-form-item>
  </el-form>
</template>

<script>
import FormItem from './FormItem.vue'
import { ref, reactive } from 'vue'
export default {
  name: 'QueryForm',
  components: {
    FormItem
  },  
  props: ['form', 'modelValue'],
  setup(props, context) {
    const queryForm = ref('')
    const queryModel = reactive({
      ...props.modelValue,
    })
    const handleReset = () => {
      queryForm.value.resetFields()
    }

    const handleQuery = () => {
      context.emit('update:modelValue', { ...queryModel })
      context.emit('handleQuery', { ...queryModel })
    }
    return {
      queryForm,
      queryModel,
      handleReset,
      handleQuery
    }
  },
}
</script>

<!-- <script setup>
import FormItem from './FormItem.vue'
import { ref, reactive } from 'vue'
const queryForm = ref('')
const props = defineProps({
  form: '',
  modelValue: '',
})
const emit = defineEmits(['handleQuery', 'update:modelValue'])
const form = props.form
const queryModel = reactive({
  ...props.modelValue,
})

const handleReset = () => {
  queryForm.value.resetFields()
}

const handleQuery = () => {
  emit('update:modelValue', { ...queryModel })
  emit('handleQuery', { ...queryModel })
}
</script> -->

<style scoped></style>
